# -*- coding: utf-8 -*-

import numpy as np
import cv2


def get_char_label(label, index):
    if int(label) == index:
        return '1'
    else:
        return '0'


def mapping_line_parser(line):
    return line.split(',')


def cut_hack_func(char_image, w, char_image_width):
    if w > 1.5 * char_image_width:
        return np.array_split(char_image, 2, axis=1)
    else:
        return [char_image]


def preprocessing(gray_img):
    # 阈值 180
    threshold = 202
    # gray_img = load_image_by_bytes(image_bytes)
    _, threshImg = cv2.threshold(gray_img, threshold, 255, cv2.THRESH_BINARY)
    return threshImg


def cut_image(image_narray):
    """
    切割图片
    :param image_narray: 要切割的图片
    :return: 返回单个字符图片列表
    """
    return image_narray[4:41, 8:42], \
           image_narray[4:41, 42:76], \
           image_narray[4:41, 76:110], \
           image_narray[4:41, 110:144]
